package com.zb.file.controller;

import com.zb.file.service.FileService;
import com.zb.result.Result;
import com.zb.utils.TokenUtil;
import com.zb.yaml.FilePath;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author WEN
 * @Date 2023/8/11 0011
 **/
@Api(tags = "附件上传类接口")
@RestController
@RequestMapping("/file/annex")
public class AnnexFileController {
    @Resource
    private FileService fileService;

    @ApiOperation("工单附件上传")
    @PostMapping("/order")
    public Result orderAnnexUpload(HttpServletRequest request, @ApiParam(value = "文件，以二进制方式上传（form-data），支持多个上传") List<MultipartFile> files) {
        return Result.success("文件上传成功").data("rows",
                fileService.orderAnnexUpload(FilePath.annexUploadPath(),
                        FilePath.domain() + FilePath.annexVisitPath(),
                        TokenUtil.getCustAccAnnexCode(request), files));
    }

    @ApiOperation("商品附件上传")
    @PostMapping("/goods")
    public Result goodsAnnexUpload(HttpServletRequest request, @ApiParam(value = "文件，以二进制方式上传（form-data），支持多个上传") List<MultipartFile> files) {
        return Result.success("文件上传成功").data("rows",
                fileService.goodsAnnexUpload(FilePath.annexUploadPath(),
                        FilePath.domain() + FilePath.annexVisitPath(),
                        TokenUtil.getCustAccAnnexCode(request), files));
    }

    @ApiOperation("知识中心附件上传")
    @PostMapping("/knowledge")
    public Result knowledgeAnnexUpload(HttpServletRequest request, @ApiParam(value = "文件，以二进制方式上传（form-data），支持多个上传") List<MultipartFile> files) {
        return Result.success("文件上传成功").data("rows",
                fileService.knowledgeAnnexUpload(FilePath.annexUploadPath(),
                        FilePath.domain() + FilePath.annexVisitPath(),
                        TokenUtil.getCustAccAnnexCode(request), files));
    }

    @ApiOperation("用户附件上传")
    @PostMapping("/user")
    public Result userAnnexUpload(HttpServletRequest request, @ApiParam(value = "文件，以二进制方式上传（form-data），支持多个上传") List<MultipartFile> files) {
        return Result.success("文件上传成功").data("rows",
                fileService.userAnnexUpload(FilePath.annexUploadPath(),
                        FilePath.domain() + FilePath.annexVisitPath(),
                        TokenUtil.getCustAccAnnexCode(request), files));
    }

    @ApiOperation("头像上传")
    @PostMapping("/avatarUpload")
    public Result avatarUpload(HttpServletRequest request, @ApiParam(value = "文件，以二进制方式上传（form-data），只能单个上传") MultipartFile file) {
        return Result.success("文件上传成功").data("rows",
                fileService.avatarUpload(FilePath.annexUploadPath(),
                        FilePath.domain() + FilePath.annexVisitPath(),
                        TokenUtil.getCustAccAnnexCode(request), file));
    }

    @ApiOperation("编码附件上传")
    @PostMapping("/codeUpload")
    public Result codeUpload(HttpServletRequest request, @ApiParam(value = "文件，以二进制方式上传（form-data），支持多个上传") List<MultipartFile> files) {
        return Result.success("文件上传成功").data("rows",
                fileService.codeUpload(FilePath.annexUploadPath(),
                        FilePath.domain() + FilePath.annexVisitPath(),
                        TokenUtil.getCustAccAnnexCode(request), files));
    }

    @ApiOperation("系统附件上传")
    @PostMapping("/sysUpload")
    public Result sysUpload(HttpServletRequest request, @ApiParam(value = "文件，以二进制方式上传（form-data），支持多个上传") List<MultipartFile> files) {
        return Result.success("文件上传成功").data("rows",
                fileService.sysUpload(FilePath.annexUploadPath(),
                FilePath.domain() + FilePath.annexVisitPath(),
                TokenUtil.getCustAccAnnexCode(request), files));
    }




}
